﻿using System.Web.UI;
using System.Linq;

namespace AutoCompleteTextBox
{
    public class AutocompleteFunctionDataSource : AutocompleteDataSource
    {
        public string ResultListLocator { get; set; }

        public string ResultTextLocator { get; set; }

        public override string RenderDataSource()
        {
            var function = Controls.OfType<LiteralControl>().FirstOrDefault();

            var so = GetSettingsObject();
            so.ClientID = ClientID.ToString();
            so.Source = function.Text;
            so.ResultListLocator = ResultListLocator;
            so.ResultTextLocator = ResultTextLocator;

            RegistrarClientScript.ClientScriptManager(Page, ClientID, so.GetString());

            return ClientID.ToString();
        }
    }
}
